package com.hr.two;

import java.util.Stack;

/**
 * @author Administrator
 */
public class JZ6_从尾到头打印链表 {
    public static int[] reversePrint(ListNode head) {
        if (head==null){
            return new int[]{};
        }
        ListNode temp=head;
        Stack<ListNode> stack=new Stack<>();
        while (temp!=null){
            stack.add(temp);
            temp=temp.next;
        }
        int size = stack.size();
        int[] res=new int[size];
        for (int i = 0; i < size; i++) {
            res[i]=stack.pop().val;
        }
        return res;
    }
    public static void main(String[] args) {
        ListNode node=new ListNode(1);
        ListNode node1=new ListNode(3);
        ListNode node2=new ListNode(2);
        node.next=node1;
        node1.next=node2;
        node2.next=null;
        for (int i : JZ6_从尾到头打印链表.reversePrint(node)) {
            System.out.println(i);
        }
    }

}
